function show(page) {
	$("input[name = 'current']").val(page);
	var form = document.forms[0];
	form.submit();
}

function previous() {
	var $page = $("input[name = 'current']");
	var page = parseInt($page.val());
	$page.val(page - 1);
	var form = document.forms[0];
	form.submit();
}

function next() {
	var $page = $("input[name = 'current']");
	var page = parseInt($page.val());
	$page.val(page + 1);
	var form = document.forms[0];
	form.submit();
}

$("document").ready(function() {
	var $pages = $(".page[id!='currentPage']");
	var original = '';
	var change = 'silver';
	$pages.hover(function() {
		original = $(this).css("background-color");
		$(this).css("background-color", change);
	}, function() {
		$(this).css("background-color", original);
	});

	var $capacity = $("input[name='capacity']");
	$page = $("input[name='current']");

	$capacity.keydown(function(event) {
		if (!$capacity.attr("readOnly")) {
			if ((event.keyCode >= 48 && event.keyCode <= 57) || event.keyCode == 8) {
				$page.val(1);
				$page.attr("readOnly", true);
				return true;
			} else if (event.keyCode == 13) {
				show(1);
			} else {
				return false;
			}
		}
	});
	$capacity.keyup(function(event) {
		if ($capacity.val() < 0) {
			$capacity.val(0);
		}
		if ($capacity.val() > 100) {
			$capacity.val(100);
		}
	});

	$page.keydown(function(event) {
		if (!$page.attr("readOnly")) {
			if ((event.keyCode >= 48 && event.keyCode <= 57) || event.keyCode == 8) {
				$capacity.attr("readOnly", true);
				return true;
			} else if (event.keyCode == 13) {
				var form = document.forms[0];
				form.submit();
			} else {
				return false;
			}
		}
	});

	var max = parseInt($("input[name='max']").val());
	$page.keyup(function(event) {
		if ($page.val() < 1) {
			$page.val(1);
		}
		if ($page.val() > max) {
			$page.val(max);
		}
	});
});